package com.parkingspace.controller;


import com.parkingspace.entity.Appraise;
import com.parkingspace.service.IAppraiseService;
import com.parkingspace.util.Constants;
import com.parkingspace.util.ResultVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 评价表 前端控制器
 * </p>
 *
 * @author Gapper
 * @since 2021-06-01
 */
@RestController
@RequestMapping("/appraise")
public class AppraiseController {

	@Resource
	private IAppraiseService iAppraiseService;

	/**
	 * 新增评价 用户ID不用传
	 * @param token 传入token
	 * @param appraise 传入信息
	 * @return 返回Boolean
	 */
	@PostMapping("/insertAppraise/{token}")
	public ResultVO insertAppraise (@PathVariable("token") String token, Appraise appraise) {
		try {
			Boolean aBoolean = iAppraiseService.insertAppraise(token, appraise);
			return new ResultVO(Constants.OPER_SUCCESS,"请求成功!",aBoolean);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResultVO(Constants.OPER_FAILURE,e.getMessage(),"请求失败!");
		}
	}

	/**
	 * 根据订单ID查询该订单的所有评价
	 * @param ordereid 传入订单ID
	 * @return 返回List
	 */
	@GetMapping("/findByOrderId/{ordereid}")
	public ResultVO findByOrderId (@PathVariable("ordereid") Long ordereid) {
		try {
			List<Appraise> byOrderId = iAppraiseService.findByOrderId(ordereid);
			return new ResultVO(Constants.OPER_SUCCESS,"请求成功!",byOrderId);
		} catch (Exception e) {
			e.printStackTrace();
			return new ResultVO(Constants.OPER_SUCCESS,e.getMessage(),0);
		}
	}

}

